local caixia = fk.CreateSkill{
  name = "wk_heg__caixia",
}

Fk:loadTranslationTable{
  ["wk_heg__caixia"] = "才瑕",
  [":wk_heg__caixia"] = "每回合限一次，当你造成或受到伤害后，你可展示任意张同名手牌，然后摸等量的牌（至多摸你体力值张）。",

  ["#wk_heg__caixia"] = "才瑕：你可以展示任意张同名手牌，然后摸等量的牌。",
  ["#wk_heg__caixia_filter"] = "",

  ["$wk_heg__caixia1"] = "吾习扫天下之术，不善净一屋之秽。",
  ["$wk_heg__caixia2"] = "玉有十色五光，微瑕难掩其瑜。",
}

local caixia_spec = {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(caixia.name) and player == target and not player:isKongcheng() and player:usedSkillTimes(caixia.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local result, dat = room:askToUseActiveSkill(player,{
        skill_name = "#wk_heg__caixia_filter",
        prompt = "#wk_heg__caixia",
        cancelable = true,
        extra_data = {skillName = caixia.name},
    })
    if result and dat then
      event:setCostData(self,{cards = dat.cards})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    player:showCards(event:getCostData(self).cards)
    if not player.dead then
      player:drawCards(math.min(#event:getCostData(self).cards, player.hp), caixia.name)
    end
  end,
}

caixia:addEffect(fk.Damaged, caixia_spec)
caixia:addEffect(fk.Damage, caixia_spec)

return caixia